String
Functions
|
|
|
|
Convert a string variable
to numerical variable.
|
|
|
|
|
**
Convert
mystring$ variable
to integer value
and store it
in RetVal
mystring$='1.222' RetVal=VAL(mystring$)
**
Convert
string variables
and count them mystring_A$='20' mystring_B$='10' RetVal=VAL(mystring_A$)
+ VAL(mystring_B$)
|
|
|
|
|
For
additional information
about VAL check
this
link.
|
|
|
|
|
|
Convert a numerical
variable to string
This type of conversion (numbers to
text) is used most often. Here's an
example of displaying advanced string
with data retrieved from numerical
variable:
|
|
|
|
|
NumOfYears=36
UserAge$=
CHAR(NumOfYears)+' years
old'
Message("Our user is
","UserAge$")
Result of these code lines will be
displayed in message box:
Our user is 36 years old
|
|
|
|
|
For
additional information
about CHAR check
this
link.
|
|
|
|
|
|
Returns the character (from
ASCII table)
with the specified ordinal
(decimal) value
(0-255).
Complete
ASCII character
table can be found
here.
|
|
|
|
|
string$=CHR(169)
+ '
Odklizec
2003'
LoadText("Text","string$")
Result of these code lines will be
displayed in Text object:
⌐ Odklizec
2003
string$=
'First
line' +
CHR(13)
+ CHR(10)
+ 'Second
line'
LoadText("Text","string$")
Result of these code lines will be
text divided into two lines:
First line Second line
|
|
|
|
|
|
Returns the ordinal (decimal) value of the specified character.
Complete
ASCII character
table can be found
here.
|
|
|
|
|
character$='#' RetVal=ORD(character$)
Result of this code will be
35
|
|
|
|
|
|
Returns the length of the specified string.
|
|
|
|
|
LoadText("string$","c:\test.txt") RetVal=LEN(string$)
Result of this
code will be length
of the loaded file.
|
|
|
|
|
|
Returns a string with the same text as the
string passed in String$ variable, but with all letters converted to
LOWercase/UPPercase.
|
|
|
|
|
string$='ThIs
TeXt WiLL bE
CoNvErtED to
LoWeRcAsE' RetString$=LOW(string$)
Result of this
code will be text
converted to lowercase.
string$='ThIs
TeXt WiLL bE
CoNvErtED to
UppErCasE' RetString$=UPP(string$)
Result of this
code will be text
converted to lowercase.
|
|
|
|
|
|
Searches for SubString within String and returns an integer value (starting
from 1) that
is the index of the first character of SubString within String.
If Substr is not found, POS returns zero.
|
|
|
|
|
string$='Have
a nice day!' substring$='nice' RetVal=POS(substring$,string$)
Result of the
above code will be
8.
|
|
|
|
|
Because POS
function (as well
as other string
functions) is case
sensitive, we recommend
you to convert the
source string to
upper or lowercase
before starting
POS
search.
string$='Have
a nice day!' substring$='have' RetString$=LOW(string$) RetVal=POS(substring$,RetString$)
If
you don't convert
the source string$
to Lowercase, then
POS
returns 0, because
'Have'<>'have'.
But after converting
string$ to Lowercase
POS
returns 1.
|
|
|
|
|
|
This function will return number of lines from FileName$.
If file doesn't exist NOL
returns zero.
|
|
|
|
|
OpenFile("txt
Files (*.txt)|*.txt|All
Files|*.*||","*.txt") If
(OpenFile$<>'')
Then RetVal=NOL(OpenFile$) End
Result of the
above code will be
number of lines
in selected file.
If none file will
be selected then
NOL
function will not
be performed.
|
|
|
|
|
|
Returns a string containing Count
characters starting with at String$[Index].
If Index is larger than the length of
String$, Copy returns an empty string.
If Count specifies more characters than are available, then
only the
characters from String$[Index] to the end of String$ are returned.
|
|
|
|
|
string$='Have
a nice day!' ReturnExt$=StrCopy(string$,1,4)
This
more advanced StrCopy
example will show
you how to make
a simple text typing
animation. Simply
insert this code
to a button and
insert new Text
object into project.
string$='Have
a nice day!' **
count number of
letters count=LEN(string$) **
create loop from
1 to number of letters For
i=1 to
count **
copy one character
per loop
ReturnExt$=StrCopy(string$,i,1)
**
pause loop
Pause("100") **
merge letters (this
will produce animation
effect)
newstring$=newstring$
+ ReturnExt$ **
load merged string
to a Text object LoadText("Text","newstring$") Next
i
|
|
|
|
|
|
Removes a substring of Count characters
from string String starting at
String[Index].
If Index is larger than the length of
String, no characters are deleted.
If Count specifies more characters than
remain starting at the String[Index], StrDel removes
the rest of the string and Returns a modified string.
|
|
|
|
|
string$='Have
a nice day!' ReturnExt$=StrDel(string$,1,5)
This
more advanced StrDel
example will show
you how to separate
Total and Free memory
obtained as a single
string from GetMemory
function.
RetMem$=GetMemory() separ$='/' **Get Total memory n=POS(separ$,RetMem$)-1 TotalMem$=StrCopy(RetMem$,0,n) n=n+1 **Get free memory FreeMem$=StrDel(RetMem$,0,n)
|
|
|
|
|
|
Merges DestStr$ into SourceStr$ at the position S[index]. Returns a
modified string.
|
|
|
|
|
sourcestr$='Have
a nice day!' deststr$='
too' **
count number of
letters count=LEN(sourcestr$) ReturnStr$=StrIns(sourcestr$,deststr$,count)
|
|
|
|
|
|
Returns the I-th character in String$.
|
|
|
|
|
string$='Have
a nice day!' count=LEN(string$) ReturnStr$=StrGet(string$,count)
|
|
|
|
|
|
Set the I-th character in String$ to character C$. Returns a
modified string.
|
|
|
|
|
string$='Have
a nice day!' count=LEN(string$) c$='!!!' ReturnStr$=StrSet(string$,count,c$)
|
|
|
|
|
|
Returns a string of length I with all
characters set to character C$.
|
|
|
|
|
c$='#' ReturnStr$=StrOfChar(c$,5)
**
use CHR for obtaining
special characters
from ASCII table c$=CHR(177) ReturnStr$=StrOfChar(c$,5)
|
|
|
|
|
|
Change all occurances of FromStr$ in String$ to
ToStr$. Returns a modified string.
|
|
|
|
|
string$='Lord
of the Rings' fromstr$='Rings' tostr$='Beer' ReturnStr$=StrChange(string$,fromstr$,tostr$)
|
|
|
|
|
|
Saves or appends the specified String$ to
the specified file. Returns 1 if succesful, 0
otherwise. If Append is True (or 1) and the specified file
does not exist, a new file is created. If Append is True (or 1) and the specified file
exist, the String$ will append
right after last character in the specified file. If LineFeed and
Append are True (or 1), then the specified string will append
on next line. If LineFeed and
Append are False (or 0), then the specified string will saved
in new file
or overwrite
the existing
one.
|
|
|
|
|
file$='c:\temp\test.txt' string$=
'this
string will
be append to
text file' ReturnVal=StrToFile(file$,string$,TRUE,FALSE)
file$='c:\temp\test.txt' For
i=1 To
10
string$=
'Line
'
+ CHAR(i)
ReturnVal=StrToFile(file$,string$,TRUE,TRUE) Next
i
|
|
|
|
|
|
This will load the entire file FileName$ (or just
single line) to string variable. FromLine is
the number of line from which will be file loaded and
NumOfLines is a number of lines that will be
loaded. If NumOfLines=-1, it will load entire file.
If NumOfLines=-1 and FromLine>0 then it will
load rest of file
fromthe line determined
by FromLine
|
|
|
|
|
file$='c:\temp\test.txt' fromline=
1 numoflines=10 ReturnStr$=StrFromFile(file$,fromline,numoflines)
|
|
|
|
|
|
ExtractExt(FileName$) Extracts the extension part of the given file name
(path).
ExtractDir(FileName$)
Extracts the drive and directory parts of the given path.
ExtractName(FileName$)
Extracts the name and extension parts of the given file name (path).
ExtractDrive(FileName$)
Returns a string containing the 'drive'
portion of a fully qualified path name for the file passed in
the FileName (path).
|
|
|
|
|
Path$='c:\MyFiles\text.txt' ReturnExt$=ExtractExt(Path$)
ReturnDir$=ExtractDir(Path$)
ReturnName$=ExtractName(Path$)
ReturnDrive$=ExtractDrive(Path$)
|
|
|
|
MMB Scripting Unleashed by
Bokzy, 2003
:: All rights reserved ::
http://www.bokzy.com
|